const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

const Warning = sequelize.define('Warning', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  userId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: 'users',
      key: 'id'
    }
  },
  location: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '地点ID或经纬度'
  },
  locationName: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '地点名称'
  },
  triggerTime: {
    type: DataTypes.DATE,
    allowNull: false,
    comment: '预警触发时间'
  },
  isCountdown: {
    type: DataTypes.BOOLEAN,
    defaultValue: false,
    comment: '是否为倒计时模式'
  },
  countdownMinutes: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: '倒计时分钟数'
  },
  isActive: {
    type: DataTypes.BOOLEAN,
    defaultValue: true,
    comment: '预警是否激活'
  },
  lastSentAt: {
    type: DataTypes.DATE,
    allowNull: true,
    comment: '上次发送时间'
  },
  createdAt: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  },
  updatedAt: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  }
}, {
  tableName: 'warnings',
  timestamps: true
});

module.exports = Warning; 